package com.liangplus.elasticsearch.service;

import com.liangplus.elasticsearch.dao.UserPDao;
import com.liangplus.elasticsearch.entity.eo.ShrEO;
import com.liangplus.elasticsearch.entity.eo.UserPEO;
import com.liangplus.elasticsearch.entity.pojo.Shr;
import com.liangplus.elasticsearch.entity.pojo.UserP;
import com.liangplus.elasticsearch.repository.ShrRepository;
import com.liangplus.elasticsearch.repository.UserPRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author liyumin
 * @date 2019/10/30
 * @description
 */
@Service
public class InitService {
    @Autowired
    private ShrRepository shrRepository;

    @Autowired
    private ShrService shrService;

    @Autowired
    private UserPRepository userPRepository;

    @Autowired
    private UserPDao userPDao;

    public void  initData(){
        List<Shr> list =  shrService.selectAll();
        List<ShrEO> lists = new ArrayList<>();
        ShrEO  shrEO = null;
        for (Shr shr:list) {
            shrEO = new ShrEO();
            shrEO.setShrCd(shr.getShrCd());
            shrEO.setShrNm(shr.getShrNm());
            shrEO.setPhoFull(shr.getPhoFull());
            shrEO.setPhoSht(shr.getPhoSht());
            lists.add(shrEO);
        }
        shrRepository.saveAll(lists);
        UserPEO userPEO = null;
        List<UserPEO> listm = new ArrayList<>();

        List<UserPEO> listm2 = new LinkedList<>();
        List<UserP> userPList = userPDao.selectAll();
        for (UserP  userP :userPList){
            userPEO = new UserPEO();
            userPEO.setUserId(userP.getUserId());
            userPEO.setSimplePNm(userP.getSimplePNm());
            userPEO.setPic(userP.getPic());
            userPEO.setOrgPic(userP.getOrgPic());
            userPEO.setPho(userP.getPho());
            userPEO.setDeviceCode(userP.getDeviceCode());
            listm.add(userPEO);
        }
        userPRepository.saveAll(listm);
    }
}
